/**
 *
 */
package de.cbf.cam.dsa.person.generator.entities;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Alti
 *
 */
public class NameData {

	protected List<NameDataPart> nameParts = new ArrayList<NameDataPart>();

	/**	 */
	public NameData() {
	}

	public String getNameString(){
		StringBuffer result = new StringBuffer();
		for (NameDataPart part : nameParts) {
			result.append(part.getText());
			result.append(" ");
		}
		return result.toString();
	}

	@Override
	public String toString() {
		return getNameString();
	}

	public List<String> getNamesByAttributes(List<String> attributes){
		List<String> result = new ArrayList<String>();
		//go through parts and decide if part is to be taken, by attributes
		for (NameDataPart part : nameParts) {
			//check for all attributes of fName part if any of desired attributes are present
			for (String attribute : attributes) {
				if(part.getAttributes().contains(attribute)){
					result.add(part.getText());
				}
			}
		}
		return result;
	}

	public List<NameDataPart> getNameParts() {
		return nameParts;
	}

	public void addNamePart(NameDataPart part){
		nameParts.add(part);
	}

	public void removeNamePart(NameDataPart part){
		nameParts.remove(part);
	}

	public void setNameParts(List<NameDataPart> nameParts) {
		this.nameParts = nameParts;
	}
}
